package com.pzhu.web.servlet;

import com.alibaba.fastjson.JSON;
import com.pzhu.domain.Brand;
import com.pzhu.service.BrandService;
import com.pzhu.service.impl.BrandServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "SelectAllServlet", value = "/SelectAllServlet")
public class SelectAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        BrandService brandService = new BrandServiceImpl();
        List<Brand> brands = brandService.selectAll();
        String brandsStr = JSON.toJSONString(brands);
        response.setContentType("text/json;charset=utf-8");

        response.getWriter().write(brandsStr);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      doGet(request,response);
    }
}
